package cn.sccl.dirms.dev.controller;

import cn.sccl.common.model.PageResult;
import cn.sccl.common.web.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import com.fasterxml.jackson.annotation.JsonView;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

import cn.sccl.dirms.dev.model.ChartSer;
import cn.sccl.dirms.dev.service.ChartSerManager;

/**
 * 的Controller
 * Created by liupan on 2017-06-25.
 */
@RestController
@RequestMapping(value = "/dirms/dev/chartSer")
public class ChartSerController extends BaseController {

    @Autowired
    private ChartSerManager chartSerManager;

    /**
     * 显示所有数据
     */
    @RequestMapping(value = "/all", method = RequestMethod.GET)
    public List<ChartSer> listAllChartSer() {
        return chartSerManager.listAll();
    }

    /**
     * 分页查询，分页参数放置在url路径中
     *
     * @param pageIndex 页码
     * @param pageSize  分页大小
     * @param request
     * @return
     */
    @RequestMapping(value = "/page/{pageIndex}/{pageSize}", method = RequestMethod.GET)
    public PageResult<ChartSer> pageQueryChartSer(@PathVariable("pageIndex") long pageIndex, @PathVariable("pageSize") int pageSize, HttpServletRequest request) {
        return chartSerManager.pageQueryByLike(pageIndex, pageSize, getQueryData(request));
    }

    /**
     * 分页查询，分页参数放置在request中
     *
     * @param request
     * @return
     */
    @RequestMapping(value = "/page", method = RequestMethod.GET)
    public PageResult<ChartSer> pageQueryChartSer(HttpServletRequest request) {
        return chartSerManager.pageQueryByLike(getPageIndex(request), getPageSize(request), getQueryData(request));
    }

    /**
     * 保存数据
     *
     * @param chartSer
     * @return
     */
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public ChartSer saveChartSer(@RequestBody ChartSer chartSer) {
        chartSerManager.save(chartSer);
        return chartSer;
    }

    /**
     * 根据ID删除数据
     *
     * @param id
     */
    @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
    @JsonView(Object.class)
    public void deleteChartSer(@PathVariable("id") String id) {
        chartSerManager.delete(id);
    }
}
